package com.acwing.partition35;

import java.io.*;

/**
 * @author rkc
 * @date 2022/8/12 9:04
 */
public class AC3449数字根 {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        while (true) {
            String x = reader.readLine();
            if ("0".equals(x)) break;
            while (x.length() > 1) {
                int y = 0;
                for (int i = 0; i < x.length(); i++) {
                    y += x.charAt(i) - '0';
                }
                x = String.valueOf(y);
            }
            writer.write(x + "\n");
        }
        writer.flush();
    }
}
